﻿using System.Collections.Generic;
using LitJson;

namespace VFramework
{
	/// <summary>
	/// 与机器交流的cmd指令，最后变成json格式
	/// </summary>
	public class MachineCmd
	{

		public delegate void MachineCB (JsonData data);


		private MachineCB cb;
		private int cmd;
		private List<int> body;



		public MachineCmd (int cmd, List<int> body, MachineCB cb)
		{
			this.cmd = cmd;
			this.body = body;
			this.cb = cb;
		}

		public string toMsg ()
		{
			JsonWriter w = new JsonWriter ();

			w.WriteObjectStart ();
			w.WritePropertyName ("id");
			w.Write (this.cmd);
			w.WritePropertyName ("pm");
			w.WriteArrayStart ();

			if (body != null) {

				for (int i = 0; i < body.Count; i++) {
					w.Write (body [i]);
				}
			}
			w.WriteArrayEnd ();
			w.WriteObjectEnd ();
			return w.ToString ();
		}



		public int getCmd ()
		{
			return cmd;
		}

		public MachineCB getCB ()
		{
			return cb;
		}
	}

}